package com.semidata.rtd.core.http.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;

import java.util.ArrayList;
import java.util.List;

public class DefaultDispatcher implements HttpDispatcher {

	private List<UrlMatcher> matchers = new ArrayList<>();;

	public DefaultDispatcher() {
	}
	
	public void addUrlMatcher(UrlMatcher matcher) {
		matchers.add(matcher);
	}

	@Override
	public HttpDispatchHandler getDispatchHandler(ChannelHandlerContext ctx,
			HttpRequest request) {
		for (UrlMatcher matcher : matchers) {
			HttpDispatchHandler handler = matcher.getDispatchHandler(ctx,
					request);
			if (handler != null)
				return handler;
		}
		return null;
	}

}
